package com.str.BT;
import java.io.*;

public class BSTTest {	
    
  public static void main(String args[]) throws IOException {
    BufferedReader stdin = new BufferedReader(
                           new InputStreamReader(System.in));
    BST intBST = new BST();

    while (true) {
      System.out.println("-------------------------");
      System.out.println("     1. Clear");      
      System.out.println("     2. Insert");    
      System.out.println("     3. Delete");
      System.out.println("     4. Contains");
      System.out.print("\tEnter your choice(Enter to quit): ");
      
      String inputLine = stdin.readLine();
      if (inputLine.equals("")) {
        System.out.println("End of run.");
        System.exit(0);
      }      
      int choice = Integer.parseInt(inputLine);

      switch (choice) {
        case 1:
          System.out.println("Cleared.");
          intBST.clear();
          break;
                	
        case 2:
          System.out.print("Enter an integer: ");
          inputLine = stdin.readLine();
          Comparable val = Integer.valueOf(inputLine);
          intBST.insert(val);
          break;

        case 3:
          System.out.print("Enter an integer: ");
          inputLine = stdin.readLine();
          val = Integer.valueOf(inputLine);
          if (intBST.contains(val)) {
            intBST.delete(val);
            System.out.println(val + " has been deleted.");
          }
          else
            System.out.println("No found " + val);          
          break;

        case 4:
          System.out.print("Enter an integer: ");
          inputLine = stdin.readLine();
          val = Integer.valueOf(inputLine);
          if (intBST.contains(val))
            System.out.println("Found " + val);
          else
            System.out.println("No found " + val);
          break;

        default:
          System.out.println("Invalid choice.");
          continue;
      }
      
      System.out.println(intBST);
      System.out.println("Size = " + intBST.size());
    }
  }
}
